package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 通过环信id查询用户数据
     *
     * @param huanxinId
     * @return
     */
    @GetMapping("/userInfo")
    public ResponseEntity userInfo(String huanxinId) {
        UserInfoVo vo = messagesService.userInfo(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 添加联系人
     *
     * @param map
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        String skr = map.get("userId").toString();
        Long friendId = Long.valueOf(skr);
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }


    /**
     * 查询联系人列表
     *
     * @param page
     * @param pagesize
     * @param keyword
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity findFriends(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      String keyword) {
        PageResult pr = messagesService.findFriends(page, pagesize, keyword);
        return ResponseEntity.ok(pr);
    }


    /**
     * 互动列表通用
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/{likes}")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize,
                                @PathVariable("likes") String likes) {
        PageResult pr = messagesService.likes(page, pagesize,likes);
        return ResponseEntity.ok(pr);
    }

    /**
     * 公告
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = messagesService.announcements(page, pagesize);
        return ResponseEntity.ok(pr);
    }
}
